<script setup lang="ts">
import { reactive, ref } from 'vue'
import type { FormInstance } from 'element-plus'
import useStore from '../../modules/store/evaluate'
import {ElMessage} from "element-plus";
let store = useStore()
const formRef = ref<FormInstance>()
const numberValidateForm = reactive({
  state: '',
  name: '',
  time: '',
  member:''
})
const options = [
  {
    value: '审核通过',
    label: '审核通过',
  },
  {
    value: '审核失败',
    label: '审核失败',
  },
  {
    value: '正在审核',
    label: '正在审核',
  }
]
const submitForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return
  formEl.validate((valid:boolean) => {
    if (valid) {
      if(numberValidateForm.name===''&&numberValidateForm.member=== ''&&numberValidateForm.state===''&&numberValidateForm.time===''){
        ElMessage({
          type: 'error',
          message: '参数不能为空'
        })
        return
      }
      console.log(numberValidateForm)
      store.searchA(numberValidateForm)
      console.log('submit!')
    } else {
      console.log('error submit!')
      return false
    }
  })
}
// 批量删除
const DeleteAll = ()=>{
    store.batch()
}
const resetForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return
  formEl.resetFields()
}
</script>

<template>
  <el-form
      style="display: flex"
      ref="formRef"
      :model="numberValidateForm"
      label-width="100px"
      class="demo-ruleForm"
  >
    <el-form-item
        label="审核状态"
        prop="key"
        :rules="[
        { required: false, message: '请填入相关信息' },
        { type: 'string', message: '需要类型匹配' },
      ]"
    >
      <el-select v-model.trim="numberValidateForm.state" clearable  class="m-2" prop="state" placeholder="Select" >
        <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
        />
      </el-select>
    </el-form-item>
    <el-form-item
        label="发布时间"
        prop="time"
        :rules="[
        { required: false, message: '请填入相关信息' },
      ]"
    >
      <el-date-picker
          v-model="numberValidateForm.time"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="Pick a day"
      />
<!--      <el-date-picker-->
<!--          type="datetime"-->
<!--          placeholder="Select date and time"-->
<!--      />-->
    </el-form-item>
    <el-form-item
        label="会员"
        prop="member"
        :rules="[
        { required: false, message: '请填入相关信息' },
        { type: 'string', message: '需要类型匹配' },
      ]"
    >
      <el-input
          v-model.trim="numberValidateForm.member"
          type="text"
          autocomplete="off"
      />
    </el-form-item>
    <el-form-item
        label="商品名称"
        prop="name"
        :rules="[
        { required: false, message: '请填入相关信息' },
        { type: 'string', message: '需要类型匹配' },
      ]"
    >
      <el-input
          v-model.trim="numberValidateForm.name"
          type="text"
          autocomplete="off"
      />
    </el-form-item>
    <el-form-item>
      <el-button class="button" type="warning" @click="submitForm(formRef)">搜索</el-button>
      <el-button type="warning" plain @click="resetForm(formRef)">重置</el-button>
      <el-button  type="warning" plain @click="DeleteAll">批量删除</el-button>
    </el-form-item>
  </el-form>
</template>

<style scoped lang="scss">

</style>
